package com.mt.api.constants.enums;

import com.mt.api.util.EnumMappingUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;

/**
 * @Author: plover
 * @Date: 2021/01/25/10:27
 * @Description: 订单状态 0-未出库 1-部分出库 2-完全出库 3-订单取消
 */
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {
    UN_OUT_STORE(0, "待出库"),
    PART_OUT_STORE(1, "部分出库"),
    COMPLETE_OUT_STORE(2, "已出库"),
    CANCEL(9, "撤销"),
    ;

    private Integer code;
    private String name;

    private static final Map<Integer, OrderStatusEnum> statusEnumMap =
            EnumMappingUtil.toMappingMap(OrderStatusEnum.class, OrderStatusEnum::getCode);

    public static OrderStatusEnum ofCode(Integer code) {
        return statusEnumMap.get(code);
    }

    public static String nameOfCode(Integer code) {
        return Objects.nonNull(statusEnumMap.get(code)) ? statusEnumMap.get(code).getName() : StringUtils.EMPTY;
    }

}
